<template >
<el-container>
  <!-- header -->
  <el-header>
    <h1>一个例子展示RotateX</h1>
  </el-header>
  <!-- main -->
  <el-main class="layout">
    <el-row>
      <el-col :span="20">
        <el-row type="flex" justify="center">
          <div class="rectangle" :style="style">
          <div class="pot"></div>
          <div class="line"></div>
          <div class="line2"></div>
        </div>
        </el-row>
      </el-col>
    </el-row>

   <el-row>
     <el-col :span="20">
          <el-form :model="form">
            <el-form-item label="x axis:" prop="x" label-width="100px">
              <el-slider v-model="form.x" :max="360" :step="10"></el-slider>
            </el-form-item>

            <el-form-item label="y axis:" prop="y" label-width="100px">
              <el-slider v-model="form.y" :max="360" :step="10"></el-slider>
            </el-form-item>

            <el-form-item label="z axis:" prop="z" label-width="100px">
              <el-slider v-model="form.z" :max="360" :step="10"></el-slider>
            </el-form-item>

            <el-form-item label="originX:" prop="originX" label-width="100px">
              <el-slider v-model="form.originX" :max="360" :step="10"></el-slider>
            </el-form-item>
            <el-form-item label="originY:" prop="originY" label-width="100px">
              <el-slider v-model="form.originY" :max="360" :step="10"></el-slider>
            </el-form-item>
            <el-form-item label="originZ:" prop="originZ" label-width="100px">
              <el-slider v-model="form.originZ" :max="360" :step="10"></el-slider>
            </el-form-item>
          </el-form>
     </el-col>
   </el-row>
  </el-main>
</el-container>

</template>

<script>
export default {
  data () {
    return {
      form: {
        x: 0,
        y: 0,
        z: 0,
        originX: 50,
        originY: 50,
        originZ: 50
      }
    }
  },
  computed: {
    style () {
      const { x, y, z, originX, originY, originZ } = this.form
      var transformStyle = [x, y, z].reduce((pre, cur, curKey) => {
        pre += ` rotate${['x', 'y', 'z'][curKey].toUpperCase()}(${
          cur || 0
        }deg)`
        return pre
      }, '')

      var transformOriginStyle = [originX, originY, originZ].reduce(
        (pre, cur) => {
          pre += ` ${cur}px`
          return pre
        },
        ''
      )

      // console.log(transformOriginStyle);
      return {
        transform: transformStyle.trim(),
        'transform-origin': transformOriginStyle.trim()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.layout {
  height: 100%;
  width: 100%;
  padding: 4% 4%;
  background-color: #fff;
  .rectangle {
    width: 400px;
    height: 200px;
    background-color: #37f;
    position: relative;
    .pot {
      position: absolute;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      left: 50%;
      top: 50%;
      transform: translate3d(-50%, -50%, 0);
      background-color: pink;
    }
    .line {
      position: absolute;
      width: 100%;
      height: 0;
      border-bottom: 1px solid red;
      border-radius: 50%;
      top: 50%;
      transform: translate3d(0, -50%, 0);
      background-color: pink;
    }
    .line2 {
      position: absolute;
      height: 100%;
      width: 0;
      border-left: 1px solid red;
      border-radius: 50%;
      left: 50%;
      transform: translate3d(-50%, 0, 0);
      background-color: pink;
    }
  }
}
</style>
